package src.algorithm;

public class NewSorting
{
    public static void main(String[] agrs) {
        //冒泡排序
        int[] sortingList = new int[]{12, 1, 2, 6, 3, 8, 9, 10, 7, 5};
        for (int i = 0; i < sortingList.length; i++) {
            for (int j = 0; j < sortingList.length - 1 - i; j++) {
                if(sortingList[j]>sortingList[j+1]){
                    int temp;
                    temp = sortingList[j];
                    sortingList[j] = sortingList[j+1];
                    sortingList[j+1] = temp;
                }
            }
        }
        for (int sum :sortingList)
            System.out.print(""+sum+",");
        System.out.println();

        //倒序输出字符串
        String inputStr = "abcdefgh";
        char[] strChar = inputStr.toCharArray();
        for(int i=strChar.length-1;i>=0;i--)
            System.out.print(strChar[i]);
        System.out.println();

        //写一个Java程序在屏幕上输出1！+2！+3！+……+10！的和
        int sum = 1;
        for (int i=1;i<=10;i++){
            int count = 1;
            for(int k=1;k<=i;k++)
                count = count * k;
            sum+=count;
        }
        System.out.println(sum);

        int i, j, mul, sum1 = 0;
        for (i = 1; i <= 10; i++) {
            mul = 1;
            for (j = 1; j <= i; j++) {
                mul = mul * j;
            }
            sum1 = sum1 + mul;
        }
        System.out.println("1！+2！+3！+……+10！= " + sum);

        //用 while 循环，计算 1~200 之间所有 3 的倍数之和。
        int ucount = 1;
        int sumofThree=0;
        while (ucount<=200){
            if(ucount%3==0)
                sumofThree += ucount;
            ucount++;
        }
        System.out.println("3的倍数："+sumofThree);

        // 用while循环，计算1~200之间所有3的倍数之和。
        int a=1;
        int sum3=0;
        while(a<=200){
            if(a%3==0)
                sum3=sum3+a;
            a++;
        }
        System.out.println("1~200之间所有3的倍数之和为:"+sum3);

    }
}
